package com.tcoiss.datafactory.controller;

import java.io.IOException;
import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tcoiss.common.log.annotation.Log;
import com.tcoiss.common.core.utils.poi.ExcelUtil;
import com.tcoiss.common.core.web.controller.BaseController;
import com.tcoiss.common.core.web.domain.AjaxResult;
import com.tcoiss.common.log.enums.BusinessType;
import com.tcoiss.common.security.annotation.PreAuthorize;
import javax.servlet.http.HttpServletResponse;
import com.tcoiss.datafactory.domain.KdSalePlanCategory;
import com.tcoiss.datafactory.service.IKdSalePlanCategoryService;
import com.tcoiss.common.core.web.page.TableDataInfo;

/**
 * 销售计划类别配置Controller
 * 
 * @author zw
 * @date 2021-06-19
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/category" )
public class KdSalePlanCategoryController extends BaseController {

    private final IKdSalePlanCategoryService iKdSalePlanCategoryService;

    /**
     * 查询销售计划类别配置列表
     */
    @PreAuthorize(hasPermi = "datafactory:category:list")
    @GetMapping("/list")
    public TableDataInfo list(KdSalePlanCategory kdSalePlanCategory) {
        startPage();
        List<KdSalePlanCategory> list = iKdSalePlanCategoryService.queryList(kdSalePlanCategory);
        return getDataTable(list);
    }

    /**
     * 导出销售计划类别配置列表
     */
    @PreAuthorize(hasPermi = "datafactory:category:export" )
    @Log(title = "销售计划类别配置" , businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,KdSalePlanCategory kdSalePlanCategory) throws IOException
    {
        List<KdSalePlanCategory> list = iKdSalePlanCategoryService.queryList(kdSalePlanCategory);
        ExcelUtil<KdSalePlanCategory> util = new ExcelUtil<KdSalePlanCategory>(KdSalePlanCategory.class);
        util.exportExcel(response,list, "category" );
    }

    /**
     * 获取销售计划类别配置详细信息
     */
    @PreAuthorize(hasPermi = "datafactory:category:query" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iKdSalePlanCategoryService.getById(id));
    }

    /**
     * 新增销售计划类别配置
     */
    @PreAuthorize(hasPermi = "datafactory:category:add" )
    @Log(title = "销售计划类别配置" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KdSalePlanCategory kdSalePlanCategory) {
        return toAjax(iKdSalePlanCategoryService.save(kdSalePlanCategory) ? 1 : 0);
    }

    /**
     * 修改销售计划类别配置
     */
    @PreAuthorize(hasPermi = "datafactory:category:edit" )
    @Log(title = "销售计划类别配置" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KdSalePlanCategory kdSalePlanCategory) {
        return toAjax(iKdSalePlanCategoryService.updateById(kdSalePlanCategory) ? 1 : 0);
    }

    /**
     * 删除销售计划类别配置
     */
    @PreAuthorize(hasPermi = "datafactory:category:remove" )
    @Log(title = "销售计划类别配置" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iKdSalePlanCategoryService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
